<template>
	<view>
		<image class="banner" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3489191538,3894566742&fm=26&gp=0.jpg"
		 mode=""></image>
		<view class="container">
			<view class="name-box">
				<view class="houtel-name">
					<view class="">
						<view class="name">
							{{hotelDetail.hotelName}}
						</view>
						<view class="addr">
							<image class="icon" src="../../static/img/4.png" mode=""></image>
							<text>{{hotelDetail.address}}</text>
						</view>
					</view>
					<view class="add1">
						<image class="icon1" src="../../static/img/11.png" mode=""></image>
						<view class="">
							{{hotelDetail.shi}} · 导航
						</view>
					</view>
				</view>
				<view class="line">

				</view>
				<view class="detail" @click="goHoutelSheShi">
					<view class="">
						酒店详情 · 设施
					</view>
					<image class="icon" src="../../static/img/7.png" mode=""></image>
				</view>
			</view>

			<view class="date" @click="onDate">
				<view class="">
					{{sM}}月{{sD}}日
				</view>
				<view class="">
					入住
				</view>
				<view class="">
					{{days}}晚
				</view>
				<view class="">
					{{eM}}月{{eD}}日
				</view>
				<view class="">
					离店
				</view>
			</view>

			<view class="tabs-box">
				<view class="tabs">
					<view v-for="(item, index) in hotelDetail.codeList" :key="index" :class="active == item.id ? 'active' : ''" @click="onActive(item.id)">
						{{item.name}}
					</view>

				</view>
				<view class="shaixuan">
					<text>筛选</text>
					<image src="../../static/img/12.png" mode=""></image>
				</view>
			</view>

			<!-- 房间信息 -->
			<view class="tabs-cont" v-if="roomList.length != 0">
				<view class="tabs-item" v-for="(item, index) in roomList" :key="index" @click="goRoomDetail">
					<image :src="item.img" mode=""></image>
					<view class="room-box">
						<view class="room-type">
							{{item.roomName}}
						</view>
						<view class="room-info">
							<text>早餐</text>
							<text>大床</text>
							<text>2-3人</text>
							<text>20m</text>
							<text>有wifi</text>
							<text>有电视</text>
						</view>
						<view class="room-price">
							<text>￥</text>
							<text>{{item.roomPrice}}</text>
						</view>
					</view>
				</view>

			</view>

			<!-- 双人床 -->
			<!-- <view class="tabs-cont" v-show="active == 2">
				<view class="tabs-item">
					<image src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3779289023,2518308653&fm=26&gp=0.jpg" mode=""></image>
					<view class="room-box">
						<view class="room-type">
							海景双人床
						</view>
						<view class="room-info">
							<text>早餐</text>
							<text>大床</text>
							<text>2-3人</text>
							<text>20m</text>
							<text>有wifi</text>
							<text>有电视</text>
						</view>
						<view class="room-price">
							<text>￥</text>
							<text>900</text>
						</view>
					</view>
				</view>
			</view> -->

			<!-- 多床房 -->
			<!-- <view class="tabs-cont" v-show="active == 3">
				<view class="tabs-item">
					<image src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3779289023,2518308653&fm=26&gp=0.jpg" mode=""></image>
					<view class="room-box">
						<view class="room-type">
							海景多人床
						</view>
						<view class="room-info">
							<text>早餐</text>
							<text>大床</text>
							<text>2-3人</text>
							<text>20m</text>
							<text>有wifi</text>
							<text>有电视</text>
						</view>
						<view class="room-price">
							<text>￥</text>
							<text>900</text>
						</view>
					</view>
				</view>
			</view> -->
		</view>
		<view class="datePicker">
			<calendar :is-fixed="false" :transition="'slide'" :init-month="2" :is-show="showDate"  mode="2"  @callback="getDate">
				<template v-slot:footer>
					<div class="date-foot" @click="sureTime">完成</div>
				</template>
			</calendar>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '../../static/utils/api.js'
	import Calendar from '@/components/mobile-calendar-simple/Calendar.vue'
	export default {
		data() {
			return {
				// 激活太
				active: 1,
				// 总的酒店数据
				hotelDetail: {
					// 类型集合
					codeList: []
				},
				// 酒店房间数据
				roomList: [],
				// 用户选择的入住日期啊，
				seclectDate: {
					startDate: '',
					endDate: ''
				},
				// 日期显示开关
				showDate: false,
				// 酒店默认显示日期
				sM: '',
				sD: '',
				eM: '',
				eD: '',
				// 住几天
				days: '1'
				
			}
		},
		components: {
			Calendar
		},
		onLoad() {
			request({
				url: 'api/fanStuProcess/detail',
				method: 'POST',
				data: {
					userId: '16e677470fe24e3c89391db8ba8a2f34',
					hotelId: '9e87cfa95d2649dfa7aeb66e4339f585'
				}
			}).then(res => {
				console.log(res);
				this.hotelDetail = res.data
				this.active = res.data.codeList[0].id
			})
			let nowTime = new Date()
			let sM = nowTime.getMonth() + 1
			let sD = nowTime.getDate()
			this.sM = sM
			this.sD = sD
			this.eM = sM
			this.eD = sD + 1
			console.log(nowTime);
			console.log(sM, sD);
		},
		methods: {
			// 切换房型
			onActive(id) {
				// console.log(id);
				// console.log(this.hotelDetail);
				this.active = id
				let arr = []
				this.hotelDetail.hotelRoomList.filter(item1 => {
					if (item1.bedType == id) {
						arr.push(item1)
					}
				})
				// console.log(arr);
				this.roomList = arr
			},
			// 跳转到房间详情页面
			goRoomDetail() {
				uni.navigateTo({
					url: '../house/roomDetail'
				})
			},
			// 跳转到设施
			goHoutelSheShi() {
				uni.navigateTo({
					url: '../house/houseSheShi?hotelid=' + this.hotelDetail.hotelId
				})
			},
			//获取回调的日期数据
			getDate(date) {
				// console.log(date)
				// 计算住了几晚
				let start = new Date(date.startStr.dateStr).getTime()
				let end =  new Date(date.endStr.dateStr).getTime()
				let days = (end - start) / 86400000
				// console.log(days);
				this.days = days
				this.seclectDate.startDate = date.startStr.dateStr
				this.seclectDate.endDate = date.endStr.dateStr
				this.sM = date.startStr.dateStr.slice(5, 7)
				this.sD = date.startStr.dateStr.slice(8, 10)
				this.eM = date.endStr.dateStr.slice(5, 7)
				this.eD = date.endStr.dateStr.slice(8, 10)
			},
			// 显示日历
			onDate() {
				this.showDate = true
			},
			// 确定日期
			sureTime() {
				if(!this.seclectDate.startDate) {
					uni.showToast({
						title: '请选择日期',
						icon: 'none'
					})
					return
				}
				this.showDate = false
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f7fb;
	}

	.banner {
		width: 100vw;

	}

	.container {
		padding: 0 30rpx;
		position: relative;
		top: -60rpx;

		.name-box {
			background-color: #fff;
			padding: 20rpx 30rpx;
			border-radius: 20rpx;

			.houtel-name {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.name {
					font-size: 32rpx;
					margin-bottom: 20rpx;
				}

				.addr {
					font-size: 28rpx;
					color: #999;
					display: flex;
					align-items: center;
				}

				.icon {
					width: 30rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}

				.icon1 {
					width: 60rpx;
					height: 60rpx;
				}

				.add1 {
					text-align: center;

					view {
						color: #999;
					}
				}
			}

			.line {
				background-color: #f6f6f6;
				height: 1px;
				margin: 20rpx 0;
			}

			.detail {
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #999;

				.icon {
					width: 20rpx;
					height: 30rpx;
				}
			}
		}

		.date {
			display: flex;
			align-items: flex-end;
			color: #6684fc;
			padding: 30rpx;
			background-color: #f0f4ff;
			border-radius: 20rpx;
			margin: 20rpx 0;

			view:nth-of-type(1) {
				font-size: 32rpx;
				margin-right: 20rpx;
			}

			view:nth-of-type(2) {
				font-size: 26rpx;
			}

			view:nth-of-type(3) {
				border: 1rpx solid #ccc;
				font-size: 24rpx;
				border-radius: 100rpx;
				padding: 0 8rpx;
				margin: 0 30rpx;
			}

			view:nth-of-type(4) {
				font-size: 32rpx;
				margin-right: 20rpx;
			}

			view:nth-of-type(5) {
				font-size: 26rpx;
			}
		}

		.tabs-box {
			display: flex;
			justify-content: space-between;

			.tabs {
				display: flex;

				view {
					font-size: 26rpx;
					padding: 10rpx 30rpx;
					border-radius: 6rpx;
					background-color: #FFFFFF;
					margin-right: 20rpx;
					color: #999;
				}

				.active {
					background-color: #6684fc;
					color: #FFFFFF;
				}
			}

			.shaixuan {
				font-size: 26rpx;
				color: #666;
				display: flex;
				align-items: center;

				image {
					width: 20rpx;
					height: 30rpx;
					margin-left: 20rpx;
				}
			}
		}

		.tabs-cont {
			.tabs-item {
				display: flex;
				background-color: #fff;
				padding: 20rpx;
				border-radius: 20rpx;
				margin-top: 20rpx;

				image {
					width: 130rpx;
					height: 130rpx;
					border-radius: 20rpx;
					margin-right: 20rpx;
				}

				.room-box {
					width: 460rpx;

					.room-type {
						font-size: 32rpx;
						margin-bottom: 10rpx;
					}

					.room-info {
						font-size: 26rpx;
						color: #999;
					}

					.room-price {
						float: right;
						color: #6684fc;

						text:nth-of-type(1) {
							font-size: 20rpx;
						}

						text:nth-of-type(2) {
							font-size: 34rpx;
							font-weight: 700;
							margin-top: 10rpx;
						}
					}
				}
			}
		}
		
	}
	.datePicker {
		position: absolute;
		top: 0;
	}
	.date-foot {
		padding: 20rpx;
		width: 90%;
		margin: 0 auto;
		background-color: #1c75ff;
		color: #fff;
		border-radius: 200px;
		text-align: center;
		
	}
	
</style>
